// 在浏览器控制台中运行的调试脚本

console.log('=== 请求调试开始 ===');

// 1. 检查当前token
const token = localStorage.getItem('token');
console.log('当前token:', token ? token.substring(0, 50) + '...' : 'null');

// 2. 直接使用fetch测试
async function testFetch() {
  console.log('测试fetch请求...');
  
  try {
    const response = await fetch('/api/menus/?search=', {
      method: 'GET',
      headers: {
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json'
      }
    });
    
    console.log('Fetch响应状态:', response.status);
    console.log('Fetch响应头:', Object.fromEntries(response.headers.entries()));
    
    const data = await response.text();
    console.log('Fetch响应内容:', data);
    
  } catch (error) {
    console.error('Fetch请求失败:', error);
  }
}

// 3. 测试axios
async function testAxios() {
  console.log('测试axios请求...');
  
  try {
    // 直接导入axios
    const axios = await import('axios');
    
    const response = await axios.default.get('/api/menus/?search=', {
      headers: {
        'Authorization': `Bearer ${token}`
      }
    });
    
    console.log('Axios响应:', response.data);
    
  } catch (error) {
    console.error('Axios请求失败:', error.response?.data || error.message);
  }
}

// 4. 测试我们的request实例
async function testRequest() {
  console.log('测试request实例...');
  
  try {
    // 导入我们的request
    const { default: request } = await import('@/utils/request');
    
    const response = await request.get('/menus/?search=');
    console.log('Request响应:', response.data);
    
  } catch (error) {
    console.error('Request请求失败:', error.response?.data || error.message);
  }
}

// 运行所有测试
testFetch();
testAxios();
testRequest();

console.log('=== 请求调试结束 ==='); 